package com.android.kalaha;

import android.widget.Button;

/**
 * Class for Cups and Kalaha
 * @author nik
 *
 */
 public class Cup extends Global{
	
	private Button button;
	private Integer beans=0; /*ff*/
	private Boolean can;
	public Integer id;
	

	
	/**
	 * Constructor: 
	 * 
	 */
	public Cup(Button button, Boolean can, Integer id){
		this.button = button;
		this.can = can;
		this.id = id;
		this.beans = null;

		// set starting amount of beans
		/* if (can==false){
			// put 4 in normal cups (0 in cans)
			this.beans = starting_beans;
			}
		*/
	}

	
	/**
	 * compare two buttons: to identify the cup
	 */
	public Boolean cmp_button(Button button){
		return button == this.button;
	}
	
	// add one bean in the cup
	public void reset(Integer cfg_starting_beans){
		this.beans = 0;
		if (this.is_can()==false){
			this.beans = cfg_starting_beans;
		}
	}
	
	public void redraw(){
		Integer beans = this.get_beans();
		if(this.button==null){
			return;
		}
		
		if (beans==null){
			this.button.setText("");
		}else{
			this.button.setText(beans.toString());
		}
	}
	
	public Boolean is_can(){
		return this.can;
	}


	/**
	 * Get the label of the cup
	 * @return
	 */
	public String get_label(){
		Integer nr = this.id + 1;
		if(nr>7){nr -= 7;}
		return "Cup" + nr.toString();
	}

	/**
	 * Get id of the cup
	 * @return Id
	 */
	public Integer get_id() {
		return id;
	}

	/**
	 * Set the id of the cup
	 * @param id
	 */
	public void set_id(Integer id) {
		this.id = id;
	}


	// activate player (its his turn)
	public void set_enable(){
		this.button.setEnabled(true);			
	}


	// activate player (its his turn)
	public void set_disable(){
		if(this.button!=null){
			this.button.setEnabled(false);
		}
	}


	/*
	 *  add one bean in the cup
	 */
	public void add_bean(){
		//this.button.setBackgroundDrawable(this.button.getBackground());
		this.beans += 1;
		
		// Animation
		//this.button.setPressed(true);
		//this.redraw();
		//this.button.setPressed(false);
	}


	// add a number of beans in the cup
	public void add_beans(Integer number){
		this.beans += number;
	}


	public Integer get_beans(){
		return this.beans;
	}


	public void set_beans(Integer beans){
		this.beans = beans;
	}


	/*
	 * Remove all beans and return the amount of the removed beans
	 */
	public Integer fetch_beans(){
		Integer handofbeans = this.beans;
		this.beans = 0;
		return handofbeans;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Cup [beans=" + beans + ", can=" + can + ", id=" + id + "]";
	}
	
	

}